<?php

/*------------------------------------------------
*
*   Explay Engine Content Management System.
*   Copyright © 2008 Golovdinov Alexander.
*
*-------------------------------------------------
*
*   Official site: wwww.alex-home.spb.ru/explay.html
*   Contact e-mail: golovdinov@gmail.com
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
------------------------------------------------*/


if (!defined ('EXPLAY')) exit;


past_path (array (array ('', 'Стартовая страница')));

if (isset($_POST['body'])) {
	$file = fopen ($_SERVER['DOCUMENT_ROOT'].'/include/start_page.txt', 'w+');
	fwrite($file, stripslashes ($_POST['body']));
	fclose ($file);
	site_message ('Стартовая страница обновлена!');
}

if ($_GET['editor'] == 'on') { mysql_query ("UPDATE site_main SET use_editor = 'on'"); $SITE['use_editor'] = "on"; }
if ($_GET['editor'] == 'off') { mysql_query ("UPDATE site_main SET use_editor = 'off'"); $SITE['use_editor'] = "off"; }

if (!file_exists ($_SERVER['DOCUMENT_ROOT'].'/include/start_page.txt')) {
	$file = fopen ($_SERVER['DOCUMENT_ROOT'].'/include/start_page.txt', 'w+');
	fclose ($file);
}

if ($SITE['use_editor'] == 'on' ) {
		print '<!-- TinyMCE -->
<script language="javascript" type="text/javascript" src="include/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
	tinyMCE.init({
		mode : "textareas",
		theme : "advanced",
		plugins : "table,save,advhr,advimage,advlink,iespell,insertdatetime,preview,zoom,searchreplace,contextmenu,paste,directionality,fullscreen",
		theme_advanced_buttons1_add_before : "save,newdocument,separator",
		theme_advanced_buttons1_add : "fontselect,fontsizeselect",
		theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
		theme_advanced_buttons2_add_before: "cut,copy,paste,pastetext,pasteword,separator,search,replace,separator",
		theme_advanced_buttons3_add_before : "tablecontrols,separator",
		theme_advanced_buttons3_add : "iespell,advhr,separator,separator,ltr,rtl,separator,fullscreen",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		content_css : "example_word.css",
	    plugi2n_insertdate_dateFormat : "%Y-%m-%d",
	    plugi2n_insertdate_timeFormat : "%H:%M:%S",
		external_link_list_url : "example_link_list.js",
		external_image_list_url : "example_image_list.js",
		media_external_list_url : "example_media_list.js",
		file_browser_callback : "fileBrowserCallBack",
		paste_use_dialog : false,
		theme_advanced_resizing : true,
		theme_advanced_resize_horizontal : false,
		theme_advanced_link_targets : "_something=My somthing;_something2=My somthing2;_something3=My somthing3;",
		paste_auto_cleanup_on_paste : true,
		paste_convert_headers_to_strong : false,
		paste_strip_class_attributes : "all",
		paste_remove_spans : false,
		paste_remove_styles : false		
	});

	function fileBrowserCallBack(field_name, url, type, win) {
		// This is where you insert your custom filebrowser logic
		alert("Filebrowser callback: field_name: " + field_name + ", url: " + url + ", type: " + type);

		// Insert new URL, this would normaly be done in a popup
		win.document.forms[0].elements[field_name].value = "someurl.htm";
	}
</script>
<!-- /TinyMCE -->';
}

$form = "<form action=\"\" method=\"post\">Редактор: ";

if ($SITE['use_editor'] == 'on') $form .=  "<a href=\"admin.php?do=start_page&editor=off\">без редактора</a> | расширенный";
else $form .=  "без редактора | <a href=\"admin.php?do=start_page&editor=on\">расширенный</a>";

$form .= "<p /><textarea name=\"body\" style=\"height: 300px; width: 100%;\">".file_get_contents($_SERVER['DOCUMENT_ROOT'].'/include/start_page.txt')."</textarea>
<p />Чтобы установить эту страницу в качестве главной страницы сайта, укажите include/start_page.php в поле &laquo;Главная страница&raquo; в <a href=\"admin.php?do=settings\">настройках сайта</a>.
<p /><span class=\"important_button\"><input style=\"width:240px\" type=\"submit\" value=\"Сохранить\" /></span>
<input onclick='javascript:window.open(\"upload.php\", \"\", \"width=500 height=300 scrollbars\");' type=\"button\" value=\"Загрузить что-нибудь\" />
</form>";

past_table ('Редактирование стартовой страницы', $form);

come_back ('панели администратора', 'admin.php');
